package com.yxym.thread_;

public class Thread02 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        Thread thread = new Thread(dog);//创建Thread对象，将dog对象放入到Thread中
        thread.start();

        Tiger tiger = new Tiger();//实现Runnable接口
        ThreadProxy threadProxy = new ThreadProxy(tiger);
        //创建Thread对象，将dog对象放入到Thread中
        threadProxy.start();
    }
}

class animal{}
@SuppressWarnings({"all"})
class Tiger extends animal implements Runnable{
    int count2 ;
    @Override
    public void run() {
        while (true){
            System.out.println("tiger方法..." + (count2++) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count2 == 10){
                break;
            }
        }
    }
}

class ThreadProxy implements Runnable{
    private Runnable target = null;//属性，类型为Runnable

    public ThreadProxy(Runnable tiger) {
        this.target = tiger;
    }

    @Override
    public void run() {
        if(target != null){
            target.run();//动态绑定，tiger(运行类型)
        }
    }

    public void start(){
        start0();//这个方法真正的实现多线程方法...
    }
    public void start0(){
        run();
    }
}

@SuppressWarnings({"all"})
class Dog implements Runnable{//通过实现接口Runnable创建线程...
    int count = 0;
    @Override
    public void run() {
        while (true){
            System.out.println("狗叫..." + (count++) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count == 10){
                break;
            }
        }
    }
}